package com.ruoyi.shebei.controller;

import java.io.InputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shebei.domain.Xunjian;
import com.ruoyi.shebei.service.IXunjianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 设备巡检记录Controller
 * 
 * @author admin
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/shebei/xunjian")
public class XunjianController extends BaseController
{
    @Autowired
    private IXunjianService xunjianService;

    /**
     * 查询设备巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:list')")
    @GetMapping("/list")
    public TableDataInfo list(Xunjian xunjian)
    {
        startPage();
        List<Xunjian> list = xunjianService.selectXunjianList(xunjian);
        return getDataTable(list);
    }

    /**
     * 导出设备巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:export')")
    @Log(title = "设备巡检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Xunjian xunjian)
    {
        List<Xunjian> list = xunjianService.selectXunjianList(xunjian);
        ExcelUtil<Xunjian> util = new ExcelUtil<Xunjian>(Xunjian.class);
        util.exportExcel(response, list, "设备巡检记录数据");
    }

    /**
     * 获取设备巡检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:query')")
    @GetMapping(value = "/{xunjianId}")
    public AjaxResult getInfo(@PathVariable("xunjianId") Long xunjianId)
    {
        return success(xunjianService.selectXunjianByXunjianId(xunjianId));
    }

    /**
     * 新增设备巡检记录
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:add')")
    @Log(title = "设备巡检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Xunjian xunjian)
    {
        return toAjax(xunjianService.insertXunjian(xunjian));
    }


    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Xunjian> util = new ExcelUtil<Xunjian>(Xunjian.class);
        util.importTemplateExcel(response, "设备巡检记录数据");
    }
    /**
     * 导入数据
     */
    @Log(title = "设备巡检记录", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<Xunjian> util = new ExcelUtil<Xunjian>(Xunjian.class);
        InputStream inputStream = file.getInputStream();
        List<Xunjian> list = util.importExcel(inputStream );
        inputStream.close();
        int count = xunjianService.batchInsertXunjian(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }


    /**
     * 修改设备巡检记录
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:edit')")
    @Log(title = "设备巡检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Xunjian xunjian)
    {
        return toAjax(xunjianService.updateXunjian(xunjian));
    }

    /**
     * 删除设备巡检记录
     */
    @PreAuthorize("@ss.hasPermi('shebei:xunjian:remove')")
    @Log(title = "设备巡检记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xunjianIds}")
    public AjaxResult remove(@PathVariable Long[] xunjianIds)
    {
        return toAjax(xunjianService.deleteXunjianByXunjianIds(xunjianIds));
    }
}
